{extend name="./app/admin/view/main.html" /}
{block name="title"}系统设置 - {__block__}{/block}
{block name="style"}
<style>
.ivu-modal-confirm-body{
	padding-left: 0;
}
</style>
<link rel="stylesheet" href="{$domainStatic}/{$assets}/admin/css/jquery.bigcolorpicker.css" type="text/css" />
{/block}

{block name="main"}
<header class="nicemip-container-header">
    <div class="float-left header-group">
        <h4 class="title">设置</h4> <h5 class="sub-title">系统设置</h5>
    </div>
    <button type="button" class="pull-right ivu-btn ivu-btn-primary ivu-btn-circle" @click='onSubmitSetting'>
        <span>立即保存</span>
    </button>
</header>

<main class="nicemip-container-body" style="height: calc(100% - 50px)">
<!-- 
<section class="nice-box">
    <section class="nice-box-heading">
        <h3>网站配置</h3>
    </section>
    <section class="nice-box-body">
        <div class="row">
            <div class="col-md-12">
                <i-form label-position="top">
                    <div class="row">
                        <div class="col-md-1">
                           <Form-item label="站点状态">
                                <i-switch v-model="setting.systemStatus">
                                    <span slot="open">开</span>
                                    <span slot="close">关</span>
                                </i-switch>
                            </Form-item>
                        </div>
                        <div class="col-md-1">
                            <Form-item label="代码压缩">
                                <i-switch v-model="setting.codeCompression">
                                    <span slot="open">开</span>
                                    <span slot="close">关</span>
                                </i-switch>
                            </Form-item>
                        </div>
                        <div class="col-md-1">
                            <Form-item label="伪静态">
                                <i-switch v-model="setting.rewrite">
                                    <span slot="open">开</span>
                                    <span slot="close">关</span>
                                </i-switch>
                            </Form-item>
                        </div>
                        <div class="col-md-1">
                            <Form-item label="UUID模式">
                                <i-switch v-model="setting.idStatus">
                                    <span slot="open">开</span>
                                    <span slot="close">关</span>
                                </i-switch>
                            </Form-item>
                        </div>
                        <div class="col-md-1">
                            <Form-item label="自定义URL">
                                <i-switch v-model="setting.diyUrlStatus">
                                    <span slot="open">开</span>
                                    <span slot="close">关</span>
                                </i-switch>
                            </Form-item>
                        </div>
                        <div class="col-md-1">
                            <Form-item label="超级站点">
                                <i-switch v-model="setting.superSites">
                                    <span slot="open">开</span>
                                    <span slot="close">关</span>
                                </i-switch>
                            </Form-item>
                        </div>
                    </div>
                </i-form>
            </div>
        </div>
    </section>
</section>
-->
 
<section class="nice-box">
    <section class="nice-box-heading">
        <h3>基本设置</h3>
    </section>
    <section class="nice-box-body">
        <div class="row">
            <div class="col-md-6">
                <i-form label-position="top">
                    <Form-item label="MIP化运行域名">
                        <i-input v-model="setting.mipDomain"></i-input>
                        <span style="color:#F00">请填写MIP化站点所使用的域名,请将该域名使用CNAME解析到如下地址 nicemip.com/test</span>
                    </Form-item>
                    <Form-item label="原网站域名">
                        <i-input v-model="setting.domain" placeholder="www.nicemip.com" disabled>
                        <i-select v-model="setting.httpType" slot="prepend" style="width: 80px" disabled>
                            <i-option value="http://">http://</i-option>
                            <i-option value="https://">https://</i-option>
                        </i-select>
                        </i-input>
                    </Form-item>
                    <Form-item label="网站名称">
                        <i-input v-model="setting.siteName"></i-input>
                    </Form-item>
                    <Form-item label="网站版权">
                        <i-input v-model="setting.siteCopyright"></i-input>
                    </Form-item>
                </i-form>
            </div>
        </div>
    </section>
</section>
<!-- 
<section class="nice-box">
    <section class="nice-box-heading">
        <h3>主题设置</h3>
    </section>
    <section class="nice-box-body">
        <div class="row">
            <div class="col-md-6">
                <i-form label-position="top">
                    
                    <Form-item label="主题颜色">
                         <input  v-model="setting.siteColor" type="text" class="ivu-input"  style=" width: 100px;" name="siteColor"   />
                        <input  id="color_b" type="bottun" readonly class="ivu-input" v-bind:style="[baseStyles]"/>
                      
                    </Form-item>
                    <Form-item label="网站Logo">
                    	 <img  :src="imgLogo" style="width:52px; margin-right:15px;">
                    	<input type="file" name="fileLogo" class="form-control"  @change="getFile($event,'logo')" style="display: none;">
                    	<button v-show="addpL" type="button" class=" ivu-btn ivu-btn-primary ivu-btn-circle" @click='addPic($event,"logo")'>
					        <span>添加图片 </span>
					    </button><font style="color:red;margin-left:15px;">(logo尺寸 52*52 推荐)</font>
					    <img v-show="addhL" src="{$domainStatic}/{$assets}/admin/images/0H1232460-0.jpg" />
                    </Form-item>
                    <Form-item label="Banner图">
                    	 <img v-for="site in imgList" :src="site" style="width:180px; margin-right:15px;">
                    	<input type="file" name="fileBanner" class="form-control" multiple  @change="getFile($event,'banner')" style="display: none;">
                    	<button v-show="addpI" type="button" class="ivu-btn ivu-btn-primary ivu-btn-circle" @click='addPic($event,"banner")'>
					        <span>添加图片</span>
					    </button>
					    <img v-show="addhI" src="{$domainStatic}/{$assets}/admin/images/0H1232460-0.jpg" />
                    </Form-item>
                   
                </i-form>
            </div>
        </div>
    </section>
</section>
-->
<section class="nice-box">
    <section class="nice-box-heading">
        <h3>首页TDK</h3>
    </section>
    <section class="nice-box-body">
        <div class="row">
            <div class="col-md-6">
                <i-form label-position="top">
                    <Form-item label="网站标题(title)">
                        <i-input v-model="setting.indexTitle" placeholder=" - 国内最大的互联网创业交流社区"></i-input>
                    </Form-item>
                    <Form-item label="网站关键词(keywords)">
                        <i-input type="textarea" v-model="setting.keywords"></i-input>
                    </Form-item>
                    <Form-item label="网站描述(description)">
                        <i-input type="textarea" v-model="setting.description"></i-input>
                    </Form-item>
                </i-form>
            </div>
        </div>
    </section>
</section>


<!-- <section class="nice-box">
    <section class="nice-box-heading">
        <h3>链接推送</h3>
    </section>
    <section class="nice-box-body">
        <i-form label-position="top">
            <div class="row">
                <div class="col-md-6">
                    <Form-item label="链接提交接口">
                        <i-input v-model="setting.baiduTimePcUrl"></i-input>
                    </Form-item>
                </div>
                <div class="col-md-2">
                   <Form-item label="链接自动推送">
                        <i-switch v-model="setting.baiduTimePcStatus">
                            <span slot="open">开</span>
                            <span slot="close">关</span>
                        </i-switch>
                    </Form-item>
                </div>
            </div>
        </i-form>
    </section>
</section> -->
<section class="nice-box">
    <section class="nice-box-heading">
        <h3>MIP推送</h3>
    </section>
    <section class="nice-box-body">
        <i-form label-position="top">
            <div class="row">
                <div class="col-md-6">
                    <Form-item label="MIP引入提交接口">
                        <i-input v-model="setting.mipApiAddress" placeholder="请到百度站长平台 移动专区->MIP引入 获取（M域名）"></i-input>
                        <a style="color:#2796ea;" href="https://ziyuan.baidu.com/mip/index" target="_blank">接口获取地址:https://ziyuan.baidu.com/mip/index</a>
                    </Form-item>
                </div>
                <div class="col-md-2">
                     <Form-item label="MIP自动推送">
                        <i-switch v-model="setting.mipPostStatus">
                            <span slot="open">开</span>
                            <span slot="close">关</span>
                        </i-switch>
                    </Form-item>
                </div>
            </div>
          
        </i-form>
    </section>
</section>

<section class="nice-box">
    <section class="nice-box-heading">
        <h3>百度站内搜索</h3>
    </section>
    <section class="nice-box-body">
        <i-form label-position="top">
            <div class="row">
                <div class="col-md-6">
                    <Form-item label="百度站内搜索Key">
                        <i-input v-model="setting.biaduZn"></i-input>
                    </Form-item>
                    <Form-item label="百度站内搜索sitemap">
                        <i-input v-model="setting.baiduSearchPcUrl"></i-input>
                    </Form-item>
                </div>
                <div class="col-md-6">
                </div>
            </div>
        </i-form>
    </section>
</section>
<section class="nice-box">
    <section class="nice-box-heading">
        <h3>其他</h3>
    </section>
    <section class="nice-box-body">
        <div class="row">
            <div class="col-md-6">
                <i-form label-position="top">
                    <Form-Item label="ICP备案号">
                        <i-input v-model="setting.icp"></i-input>
                    </Form-Item>
                    <Form-Item label="流量统计代码">
                        <i-input type="textarea" v-model="setting.statistical"></i-input>
                    </Form-Item>
                </i-form>
            </div>
            <div class="col-md-6">
                <i-form label-position="top">
                    <Form-Item label="备注说明：">
                        您输入的流量统计代码必须符合MIP标准，否则将对整站页面造成MIP校验不合格问题，默认支持百度统计，其余统计请查看官方标准。输入示例：<br>{{codeDemo}}
                    </Form-Item>
                </i-form>

            </div>
        </div>
    </section>
</section>
</main>
{/block}
    
{block name="javascript"}
{__block__}
<script src="{$domainStatic}/{$assets}/admin/js/jquery.bigcolorpicker.js"></script>
<script>
    new Vue({
        el: '#app',
        data: {
        	 setting: '',
             codeDemo: '<mip-stats-baidu token="02890d4a309827eb62bc3335b2b28f7f"></mip-stats-baidu>',
             baseStyles:{
 					width: '25px',
 				    height: '25px',
 				    padding: '0px',
 				    border: '0px',
 				    cursor: 'pointer',
             },
             rePing:'',

        },
        watch: {
        },
        mounted() {
            this.getSettingData();
        },
        methods: {
            onSubmitSetting: function() {
            	var _this = this;
            	//域名验证 
            	_this.Ping(this.setting.mipDomain);
                this.$nicemip.ajax('{$domain}/setting/ApiAdminSetting/settingEdit', {
                    setting: JSON.stringify(this.setting),
                }).then(function(res) {
                    if(res.code == 1) {
                    	if(_this.rePing == 1){
							_this.$Modal.confirm({
			                    title: '消息提示',
			                    content: '<p>保存成功 如果您需要修改  请前往网站管理的站点设置里面进行修改</p>',
			                    onOk: () => {
			                        window.location.href = '{$domain}/{$Think.config.admin}/setting/setting/';
			                    }, 
			                    onCancel: () => {
			                        window.location.href = '{$domain}/{$Think.config.admin}/setting/setting/';
			                    }
			                  });
                    	}else{
                    		_this.$Modal.confirm({
			                    title: '消息提示',
			                    content: '<p>您的域名还没有解析成功，请将该域名使用cna的方式解析到如下地址 nicemip.com/test  然后进入到网站管理进行域名绑定</p>',
			                    onOk: () => {
			                        window.location.href = '{$domain}/{$Think.config.admin}/setting/setting/';
			                    }, 
			                    onCancel: () => {
			                        window.location.href = '{$domain}/{$Think.config.admin}/setting/setting/';
			                    }
			                });
                    	}
                    }
                });
            },
            getSettingData: function() {
                var _this = this;
                this.loading = true;
                this.$nicemip.ajax('{$domain}/setting/ApiAdminSetting/settingSelect', {

                }).then(function(res) {
                    _this.loading = false;
                    if(res.code == 1) {
                        var temp = res.data;
                        if(temp.systemStatus) {
                            temp.systemStatus = true;
                        } else {
                            temp.systemStatus = false;
                        }
                        if(temp.loginStatus) {
                            temp.loginStatus = true;
                        } else {
                            temp.loginStatus = false;
                        }
                        if(temp.registerStatus) {
                            temp.registerStatus = true;
                        } else {
                            temp.registerStatus = false;
                        }
                        if(temp.idStatus) {
                            temp.idStatus = true;
                        } else {
                            temp.idStatus = false;
                        }
                        if(temp.codeCompression) {
                            temp.codeCompression = true;
                        } else {
                            temp.codeCompression = false;
                        }
                        if(temp.baiduSpider) {
                            temp.baiduSpider = true;
                        } else {
                            temp.baiduSpider = false;
                        }
                        if(temp.articlePages) {
                            temp.articlePages = true;
                        } else {
                            temp.articlePages = false;
                        }
                        if(temp.mipPostStatus) {
                            temp.mipPostStatus = true;
                        } else {
                            temp.mipPostStatus = false;
                        }
                        if(temp.baiduYuanChuangStatus) {
                            temp.baiduYuanChuangStatus = true;
                        } else {
                            temp.baiduYuanChuangStatus = false;
                        }
                        if(temp.guanfanghaoStatus) {
                            temp.guanfanghaoStatus = true;
                        } else {
                            temp.guanfanghaoStatus = false;
                        }
                        if(temp.guanfanghaoStatusPost) {
                            temp.guanfanghaoStatusPost = true;
                        } else {
                            temp.guanfanghaoStatusPost = false;
                        }

                        if(temp.baiduTimePcStatus) {
                            temp.baiduTimePcStatus = true;
                        } else {
                            temp.baiduTimePcStatus = false;
                        }
                        if(temp.baiduTimeMStatus) {
                            temp.baiduTimeMStatus = true;
                        } else {
                            temp.baiduTimeMStatus = false;
                        }
                        if(temp.diyUrlStatus) {
                            temp.diyUrlStatus = true;
                        } else {
                            temp.diyUrlStatus = false;
                        }
                        if(temp.urlCategory) {
                            temp.urlCategory = true;
                        } else {
                            temp.urlCategory = false;
                        }

                        if(temp.aritcleLevelRemove) {
                            temp.aritcleLevelRemove = true;
                        } else {
                            temp.aritcleLevelRemove = false;
                        }

                        if(temp.superSites) {
                            temp.superSites = true;
                        } else {
                            temp.superSites = false;
                        }
                        
                        if(temp.superTpl) {
                            temp.superTpl = true;
                        } else {
                            temp.superTpl = false;
                        }

                        if(temp.rewrite) {
                            temp.rewrite = true;
                        } else {
                            temp.rewrite = false;
                        }
                        temp.baiduSearchPcUrl = '/baiduSitemapPc.xml';
                       
                        _this.setting = temp;
                    }
                });
            },
          //模拟ping功能
            Ping:function(ip){
            	_this = this;
            	var img = new Image();
			    var start = new Date().getTime();
			    var flag = false;
			    var isCloseWifi = true;
			    var hasFinish = false;

			    img.onload = function() {
			        if ( !hasFinish ) {
			            flag = true;
			            hasFinish = true;
			            console.log('Ping ' + ip + ' success1. ');
			            window.open('{$webUrl}');
			            window.location.href = '{$domain}/{$Think.config.admin}';
			        }
			    };

			    img.onerror = function() {
			        if ( !hasFinish ) {
			            if ( !isCloseWifi ) {
			                flag = true;
			                console.log('Ping ' + ip + ' success2. ');
			                 _this.rePing = 1;
			               
			            } else {
			                console.log('network is not working!');
			            }
			            hasFinish = true;
			        }
			    };


			    setTimeout(function(){
			        isCloseWifi = false;
			        console.log('network is working, start ping...');
			    },2);

			    img.src = 'http://' + ip + '/' + start;
			    var timer = setTimeout(function() {
			        if ( !flag ) {
			            hasFinish = true;
			            flag = false ;
			            console.log('Ping ' + ip + ' fail. ');
			            _this.rePing = 0;
			        }
			    }, 1500);	
            }
           

        }
    })
  </script>

{/block}